package com.xuedakun.xasdk.net.okhttp.upload;

import java.util.LinkedList;

/**
 * Created by xuedakun on 2017/6/6 16:40
 * 上传管理
 *
 * @version : v1.0
 * @project : xasdk
 * @Email : dakun611@Gmail.com
 */

public class UploadManager {

    private static final String LOG_TAG = "UploadManager";

    /**
     * 等待上传
     */
    public static final int STATUS_WAIT = 0;

    /**
     * 上传中
     */
    public static final int STATUS_LOAD = 1;

    /**
     * 暂停上传
     */
    public static final int STATUS_PAUSE = 2;

    /**
     * 上传失败
     */
    public static final int STATUS_FAIL = 3;

    private static UploadManager instance;

    private UploadHttpHelp help;

    /**
     * 上传队列
     */
    private LinkedList<UploadTask> uploadQueue = new LinkedList<>();

    private UploadManager() {
        help = new UploadHttpHelp();
    }

    public static UploadManager getInstance() {
        synchronized (UploadManager.class) {
            if (instance == null) {
                instance = new UploadManager();
            }
            return instance;
        }
    }

    /**
     * 添加上传任务
     */
    public void upload(UploadTask task) {
        if(task != null) {
            uploadQueue.add(task);

            help.doRequest(task.getUrl(), task.getHeaders(), task.getArguments(), task.getKey(), task.getFile(), task.getUploadListener());


        }
    }
}
